<template>
  <div id="name">
    <div class="wl-body">
      <div class="bdds mtpo">
        <div>
          <div class="gd">
            <div class="gg-t ml-3">{{ $t("m.wt") }}</div>
            <div>
              <textarea
                cols="8"
                rows="20"
                class="bkly"
                v-model="content"
              ></textarea>
            </div>
            <div class="gg t-left ml-3">{{ $t("m.wtpi") }}</div>
          </div>
          <div class="gd">
            <div class="gg-t ml-3">{{ $t("m.wtjt") }}</div>
            <div class="gg-t m-1 ml-3">
              <van-uploader v-model="fileList" :after-read="afterRead">
                <img src="../assets/timg/addimg.png" alt="" />
                <template #preview-cover="{ file }">
                  <div class="preview-cover van-ellipsis">{{ file.name }}</div>
                </template>
              </van-uploader>
            </div>
            <div class="bdds">
              <div class="btnsd scllow w35 mtpo" @click="gdtj()">
                {{ $t("m.tj") }}
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "name",
  data() {
    return {
      isPublish: false,
      acchange: 0,
      acchangew: 0,
      content: "",
      oid: "",
      fileList: [],
      imglist: [],
    };
  },
  created() {
    this.oid = sessionStorage.getItem("gddata");
  },
  methods: {
    afterRead(file) {
      var f = new FormData();
      f.append("file", file.file);
      this.$post({
        url: "file/qCloudMultipartFileUpload",
        data: f,
        callback: (data) => {
          this.$nextTick(function () {
            var s = data;
            if (s) {
              this.imglist.push(s);
              console.log(this.imglist);
            } else {
              this.$toast(data.message);
            }
          });
        },
      }).catch(() => {
        this.$toast(this.$i18n.t("m.errordata"));
      });
    },

    guanbi() {
      this.$router.go(-1);
    },
    changers(val) {
      this.acchange = val;
    },
    changersw(val) {
      this.acchangew = val;
    },
    goto(val) {
      this.$router.push({ path: val });
    },
    gdtj() {
      if (!this.content) {
        this.$toast(this.$i18n.t("m.xxtxwz"));
        return;
      }
      if (this.$store.getters.nameid) {
        let datas = {
          oid: this.oid,
          uid: this.$store.getters.nameid,
          content: this.content,
          imgs: this.imglist.join(","),
          type: 1,
        };
        this.$post({
          url: "workOrder/createWorkContent",
          data: datas,
          callback: (data) => {
            this.$nextTick(function () {
              var s = data.data;
              if (s) {
                this.$toast(this.$i18n.t("m.gdtjsuc"));
                setTimeout(() => {
                  this.$router.push({ path: "gdxq" });
                }, 1000);
              } else {
                this.$toast(data.message);
              }
            });
          },
        }).catch(() => {
          this.suoding = false;
          this.$toast(this.$i18n.t("m.errordata"));
        });
      } else {
        this.getuid();
      }
    },
    getuid() {
      this.$get({
        url: "wms-wallet/user-game-info/" + this.$store.getters.userWallet,
        data: {},
        callback: (data) => {
          this.$nextTick(function () {
            if (data.data) {
              this.$store.commit("nameid", data.data.id);
              this.onLoad();
            }
          });
        },
      }).catch(() => {
        this.$toast(this.$i18n.t("m.errordata"));
      });
    },
  },
};
</script>

<style lang="scss" scoped>
</style>